package edu.ynu.se.xiecheng.achitectureclass.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import edu.ynu.se.xiecheng.achitectureclass.common.entity.LogicEntity;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.Set;

@Entity
@Getter
@Setter
@Where(clause = "is_deleted = 0")
public class Greenhouse extends LogicEntity {

    @Column
    private String greenhouseName;
    @Column
    private String greenhouseArea;
    @Column
    private String greenhouseLocation;
    @Column
    private String cameraToken;
    @Column
    private Long cameraTokenExpireTime;

    @OneToMany(mappedBy = "greenhouse",
            fetch = FetchType.LAZY,
            cascade = CascadeType.ALL)
    @JsonIgnoreProperties("greenhouse")
    private Set<Device> devices;

    public void addDevice(Device device) {
        device.setGreenhouse(this);
        devices.add(device);
    }

}
